define(['moment'], function () {
    return ['$scope', '$rootScope', '$filter', '$stateParams', '$mdDialog', 'config', 'MMWService', '$calculater',
        function ($scope, $rootScope, $filter, $stateParams, $mdDialog, config, $MMWService, $calculater) {

            $scope.init = function () {
                var content = {
                    plot_check_in: []
                };

                $MMWService.PNIGList = {};
                $scope.warehouseInfo = {
                    type: '', product_warehouse: '', storage: '',
                    plot_info_detail: [],
                    plot_detail: [],
                    plot_check_in: [],
                    wo_no: '', item_no: '', plot_no: '', erp_doc_type: ''
                };
                $scope.sn_no = '';

                $scope.type = '0';
                $scope.selectedList = [];
                $scope.plot_info_detail = [];

                $scope.warehouseInfo.item_no = '';
                $scope.warehouseInfo.item_name = '';
                $scope.warehouseInfo.wo_no = '';

                $scope.warehouseInfo.select_type = 3;

                $scope.list_filter = {};
                $scope.filterSH = {};
                $scope.feedback_type = [];
                $scope.do_flag = 0;
                $scope.changeNumOrNot = 0;               
            };

            $scope.back = function () {
                $scope.$root.hideMenu();
                $scope.$root.changeProgram('home', true);
            };

            // 标签条码輸入
            $scope.input_sn_no = function (event) {
                if (event.keyCode == 13) {

                    //标签条码的卡控
                    var content = {
                        barcode: $scope.sn_no
                       
                    };
                    $MMWService.sendToServer({
                        uri: 'ServicesSTD.Module_SN.check_barcode',
                        content: content,
                        success: function (data) {
                           
                            if (data.Main[0].instate == 1) {
                                $scope.$root.showConfirm($filter('translate')('B0405.msg.whether_selected'), function (dialog) {
                                    dialog.hide();
                                    //确定按钮
                                    if ($scope.warehouseInfo.plot_info_detail.length > 0) {
                                        var count = 0
                                        $scope.warehouseInfo.plot_info_detail.forEach(function (item) {
                                            if (item.barcode == data.Main[0].barcode) {
                                                count = count + 1;
                                            }

                                        });
                                        if (count == 0) {
                                            $scope.warehouseInfo.plot_info_detail.push(data.Main[0]);
                                            for (var i = 0 ; i < data.detail.length; i++) {
                                                $scope.selectedList.push(data.detail[i]);
                                            }
                                            data.plot_info_detail.forEach(function (item) {
                                            //if ($scope.warehouseInfo.plot_check_in.length == 0) {
                                            //20220922 modify by wangqq for M#119454；标签入库录入所有明细
                                            // 20230720 modify by wenwei for M#141123  三张标签不能一起扫码入库
                                            const has_same_lotno = $scope.warehouseInfo.plot_check_in.some(i => i.lotno === item.lotno)
                                            if(!has_same_lotno){
                                                    //20220518 add by 翰鴻 for M#110301                                                
                                                    item.product_no = data.Main[0].productno;
                                                    item.product_ver = data.Main[0].productversion;
                                                    item.opno = data.Main[0].opno;
                                                    $scope.warehouseInfo.plot_check_in.push(item);
                                                } else {
                                                    for (var i = 0 ; i < $scope.warehouseInfo.plot_check_in.length; i++) {
                                                        if ($scope.warehouseInfo.plot_check_in[i].lotno == item.lotno) {
                                                            $scope.warehouseInfo.plot_check_in[i].lotno_qty = $scope.warehouseInfo.plot_check_in[i].lotno_qty + item.lotno_qty
                                                        }
                                                    }

                                                }

                                            });
                                        }
                                        $scope.warehouseInfo.plot_detail = $scope.warehouseInfo.plot_check_in;
                                        $scope.sn_no = '';
                                    } else {
                                        $scope.warehouseInfo.plot_info_detail = data.Main;
                                        $scope.selectedList = data.detail;
                                        data.plot_info_detail.forEach(function (item) {
                                            // if ($scope.warehouseInfo.plot_check_in.length == 0) {
                                            //20220922 modify by wangqq for M#119454；标签入库录入所有明细
                                            // 20230720 modify by wenwei for M#141123  三张标签不能一起扫码入库
                                            const has_same_lotno = $scope.warehouseInfo.plot_check_in.some(i => i.lotno === item.lotno)
                                            if(!has_same_lotno){
                                                //20220518 add by 翰鴻 for M#110301                                                
                                                item.product_no = data.Main[0].productno;
                                                item.product_ver = data.Main[0].productversion;
                                                item.opno = data.Main[0].opno;
                                                $scope.warehouseInfo.plot_check_in.push(item);
                                            } else {
                                                for (var i = 0 ; i < $scope.warehouseInfo.plot_check_in.length; i++) {
                                                    if ($scope.warehouseInfo.plot_check_in[i].lotno == item.lotno) {
                                                        $scope.warehouseInfo.plot_check_in[i].lotno_qty = parseInt($scope.warehouseInfo.plot_check_in[i].lotno_qty) + parseInt(item.lotno_qty)
                                                    }
                                                }

                                            }

                                        });
                                        $scope.warehouseInfo.plot_detail = $scope.warehouseInfo.plot_check_in;
                                        $scope.sn_no = '';
                                    }
                                }, function (dialog) {
                                    dialog.hide();
                                    //取消按钮
                                    $scope.sn_no = '';
                                });

                            } else {
                                if ($scope.warehouseInfo.plot_info_detail.length > 0) {
                                    var count =0
                                    $scope.warehouseInfo.plot_info_detail.forEach(function (item) {
                                        if (item.barcode == data.Main[0].barcode) {
                                            count = count + 1;
                                        }

                                    });
                                    if (count == 0) {
                                        $scope.warehouseInfo.plot_info_detail.push(data.Main[0]);
                                        for (var i = 0 ; i < data.detail.length; i++) {
                                            $scope.selectedList.push(data.detail[i]);
                                        }
                                        data.plot_info_detail.forEach(function (item) {
                                            // if ($scope.warehouseInfo.plot_check_in.length == 0) {
                                            //20220922 modify by wangqq for M#119454；标签入库录入所有明细
                                            // 20230720 modify by wenwei for M#141123  三张标签不能一起扫码入库
                                            const has_same_lotno = $scope.warehouseInfo.plot_check_in.some(i => i.lotno === item.lotno)
                                            if(!has_same_lotno){
                                                //20220518 add by 翰鴻 for M#110301                                                
                                                item.product_no = data.Main[0].productno;
                                                item.product_ver = data.Main[0].productversion;
                                                item.opno = data.Main[0].opno;
                                                $scope.warehouseInfo.plot_check_in.push(item);
                                            } else {
                                                for (var i = 0 ; i < $scope.warehouseInfo.plot_check_in.length; i++) {
                                                    if ($scope.warehouseInfo.plot_check_in[i].lotno == item.lotno) {
                                                        $scope.warehouseInfo.plot_check_in[i].lotno_qty = $scope.warehouseInfo.plot_check_in[i].lotno_qty + item.lotno_qty
                                                    }
                                                }

                                            }

                                        });
                                    }                                                                                                         
                                    $scope.warehouseInfo.plot_detail = $scope.warehouseInfo.plot_check_in;
                                    $scope.sn_no = '';
                                } else {
                                    $scope.warehouseInfo.plot_info_detail = data.Main;
                                    $scope.selectedList = data.detail;                                    
                                    data.plot_info_detail.forEach(function (item) {
                                        // if ($scope.warehouseInfo.plot_check_in.length == 0) {
                                        //20220922 modify by wangqq for M#119454；标签入库录入所有明细
                                        // 20230720 modify by wenwei for M#141123  三张标签不能一起扫码入库
                                        const has_same_lotno = $scope.warehouseInfo.plot_check_in.some(i => i.lotno === item.lotno)
                                        if(!has_same_lotno){
                                            //20220518 add by 翰鴻 for M#110301                                                
                                            item.product_no = data.Main[0].productno;
                                            item.product_ver = data.Main[0].productversion;
                                            item.opno = data.Main[0].opno;
                                            $scope.warehouseInfo.plot_check_in.push(item);
                                        } else {
                                            for (var i = 0 ; i < $scope.warehouseInfo.plot_check_in.length; i++) {
                                                if ($scope.warehouseInfo.plot_check_in[i].lotno == item.lotno) {
                                                    $scope.warehouseInfo.plot_check_in[i].lotno_qty = parseInt($scope.warehouseInfo.plot_check_in[i].lotno_qty) + parseInt(item.lotno_qty)
                                                }
                                            }

                                        }

                                    });
                                    $scope.warehouseInfo.plot_detail = $scope.warehouseInfo.plot_check_in;
                                    $scope.sn_no = '';
                                }                                
                                return;
                            }
                        }
                    });
                }
            };


             //标签扫码
             $scope.SNCodeScanner = function () {
                $scope.$root.OpenScanner({
                    after: function (result) {
                        $scope.sn_no = result.text;
                       
                        var content = {
                            barcode: $scope.sn_no

                        };
                        $MMWService.sendToServer({
                            uri: 'ServicesSTD.Module_SN.check_barcode',
                            content: content,
                            success: function (data) {

                                if (data.Main[0].instate == 1) {
                                    $scope.$root.showConfirm($filter('translate')('B0405.msg.whether_selected'), function (dialog) {
                                        dialog.hide();
                                        //确定按钮
                                        if ($scope.warehouseInfo.plot_info_detail.length > 0) {
                                            var count = 0
                                            $scope.warehouseInfo.plot_info_detail.forEach(function (item) {
                                                if (item.barcode == data.Main[0].barcode) {
                                                    count = count + 1;
                                                }

                                            });
                                            if (count == 0) {
                                                $scope.warehouseInfo.plot_info_detail.push(data.Main[0]);
                                                for (var i = 0 ; i < data.detail.length; i++) {
                                                    $scope.selectedList.push(data.detail[i]);
                                                }
                                                data.plot_info_detail.forEach(function (item) {
                                                    // if ($scope.warehouseInfo.plot_check_in.length == 0) {
                                                    //20220922 modify by wangqq for M#119454；标签入库录入所有明细
                                                    // 20230720 modify by wenwei for M#141123  三张标签不能一起扫码入库
                                                    const has_same_lotno = $scope.warehouseInfo.plot_check_in.some(i => i.lotno === item.lotno)
                                                    if(!has_same_lotno){
                                                        //20220518 add by 翰鴻 for M#110301                                                
                                                        item.product_no = data.Main[0].productno;
                                                        item.product_ver = data.Main[0].productversion;
                                                        item.opno = data.Main[0].opno;
                                                        $scope.warehouseInfo.plot_check_in.push(item);
                                                    } else {
                                                        for (var i = 0 ; i < $scope.warehouseInfo.plot_check_in.length; i++) {
                                                            if ($scope.warehouseInfo.plot_check_in[i].lotno == item.lotno) {
                                                                $scope.warehouseInfo.plot_check_in[i].lotno_qty = $scope.warehouseInfo.plot_check_in[i].lotno_qty + item.lotno_qty
                                                            }
                                                        }

                                                    }

                                                });
                                            }
                                            $scope.warehouseInfo.plot_detail = $scope.warehouseInfo.plot_check_in;
                                            $scope.sn_no = '';
                                        } else {
                                            $scope.warehouseInfo.plot_info_detail = data.Main;
                                            $scope.selectedList = data.detail;
                                            data.plot_info_detail.forEach(function (item) {
                                                // if ($scope.warehouseInfo.plot_check_in.length == 0) {
                                                //20220922 modify by wangqq for M#119454；标签入库录入所有明细
                                                // 20230720 modify by wenwei for M#141123  三张标签不能一起扫码入库
                                                const has_same_lotno = $scope.warehouseInfo.plot_check_in.some(i => i.lotno === item.lotno)
                                                if(!has_same_lotno){
                                                    //20220518 add by 翰鴻 for M#110301                                                
                                                    item.product_no = data.Main[0].productno;
                                                    item.product_ver = data.Main[0].productversion;
                                                    item.opno = data.Main[0].opno;
                                                    $scope.warehouseInfo.plot_check_in.push(item);
                                                } else {
                                                    for (var i = 0 ; i < $scope.warehouseInfo.plot_check_in.length; i++) {
                                                        if ($scope.warehouseInfo.plot_check_in[i].lotno == item.lotno) {
                                                            $scope.warehouseInfo.plot_check_in[i].lotno_qty = parseInt($scope.warehouseInfo.plot_check_in[i].lotno_qty) + parseInt(item.lotno_qty)
                                                        }
                                                    }

                                                }

                                            });
                                            $scope.warehouseInfo.plot_detail = $scope.warehouseInfo.plot_check_in;
                                            $scope.sn_no = '';
                                        }
                                    }, function (dialog) {
                                        dialog.hide();
                                        //取消按钮
                                        $scope.sn_no = '';
                                    });

                                } else {
                                    if ($scope.warehouseInfo.plot_info_detail.length > 0) {
                                        var count = 0
                                        $scope.warehouseInfo.plot_info_detail.forEach(function (item) {
                                            if (item.barcode == data.Main[0].barcode) {
                                                count = count + 1;
                                            }

                                        });
                                        if (count == 0) {
                                            $scope.warehouseInfo.plot_info_detail.push(data.Main[0]);
                                            for (var i = 0 ; i < data.detail.length; i++) {
                                                $scope.selectedList.push(data.detail[i]);
                                            }
                                            data.plot_info_detail.forEach(function (item) {
                                                // if ($scope.warehouseInfo.plot_check_in.length == 0) {
                                                //20220922 modify by wangqq for M#119454；标签入库录入所有明细
                                                // 20230720 modify by wenwei for M#141123  三张标签不能一起扫码入库
                                                const has_same_lotno = $scope.warehouseInfo.plot_check_in.some(i => i.lotno === item.lotno)
                                                if(!has_same_lotno){
                                                    //20220518 add by 翰鴻 for M#110301                                                
                                                    item.product_no = data.Main[0].productno;
                                                    item.product_ver = data.Main[0].productversion;
                                                    item.opno = data.Main[0].opno;
                                                    $scope.warehouseInfo.plot_check_in.push(item);
                                                } else {
                                                    for (var i = 0 ; i < $scope.warehouseInfo.plot_check_in.length; i++) {
                                                        if ($scope.warehouseInfo.plot_check_in[i].lotno == item.lotno) {
                                                            $scope.warehouseInfo.plot_check_in[i].lotno_qty = $scope.warehouseInfo.plot_check_in[i].lotno_qty + item.lotno_qty
                                                        }
                                                    }

                                                }

                                            });
                                        }
                                        $scope.warehouseInfo.plot_detail = $scope.warehouseInfo.plot_check_in;
                                        $scope.sn_no = '';
                                    } else {
                                        $scope.warehouseInfo.plot_info_detail = data.Main;
                                        $scope.selectedList = data.detail;
                                        data.plot_info_detail.forEach(function (item) {
                                            // if ($scope.warehouseInfo.plot_check_in.length == 0) {
                                            //20220922 modify by wangqq for M#119454；标签入库录入所有明细
                                                // 20230720 modify by wenwei for M#141123  三张标签不能一起扫码入库
                                                const has_same_lotno = $scope.warehouseInfo.plot_check_in.some(i => i.lotno === item.lotno)
                                                if(!has_same_lotno){
                                                //20220518 add by 翰鴻 for M#110301                                                
                                                item.product_no = data.Main[0].productno;
                                                item.product_ver = data.Main[0].productversion;
                                                item.opno = data.Main[0].opno;
                                                $scope.warehouseInfo.plot_check_in.push(item);
                                            } else {
                                                for (var i = 0 ; i < $scope.warehouseInfo.plot_check_in.length; i++) {
                                                    if ($scope.warehouseInfo.plot_check_in[i].lotno == item.lotno) {
                                                        $scope.warehouseInfo.plot_check_in[i].lotno_qty = parseInt($scope.warehouseInfo.plot_check_in[i].lotno_qty) + parseInt(item.lotno_qty)
                                                    }
                                                }

                                            }

                                        });
                                        $scope.warehouseInfo.plot_detail = $scope.warehouseInfo.plot_check_in;
                                        $scope.sn_no = '';
                                    }

                                    return;
                                }
                            }
                        });
                       
                    },
                    exception: function () {
                        //目前裝置無法使用相機
                        $scope.$root.showAlert($filter('translate')('B0214.showAlert.column3'));
                    },
                    orientation: 'landscape'
                });

            }


            $scope.decideChange = function(){
                if($scope.changeNumOrNot==0){
                    $scope.changeNumOrNot=1;
                }else{
                    $scope.changeNumOrNot=0;
                }
            }

            $scope.confirm = function () {
                $scope.warehouseInfo.product_warehouse = '';//成品庫
                $scope.warehouseInfo.product_warehouse_name = '';//成品庫
                $scope.warehouseInfo.storage = ''; //儲位
                $scope.warehouseInfo.storage_display = ''; //儲位
                $scope.warehouseInfo.erp_doc_type = '';//ERP單別
                $scope.openStorage();
                
            };
                            
                function check_select_list(click_data,key){//如果已選清單有該則入庫項目，清掉原項目並新增該項目
                    if(typeof(key) == 'number' && key!==-1){
                        $scope.selectedList.splice(key,1);
                    }
                    $scope.selectedList.unshift(click_data);
                }

                function check_select_list_repeat(data){
                    let repeatStorage = -1;
                    $scope.selectedList.forEach(function(item,key){
                        if(item.wo_no === data.wo_no && item.plot_no === data.plot_no && item.item_name === data.item_name){
                            //有重複輸入
                            repeatStorage = key; 
                        }    
                    });
                    return repeatStorage;
                }

                $scope.itemCheck = function (index, data) {

                    //删除上面Main
                    var _index = $scope.warehouseInfo.plot_info_detail.indexOf(data);
                    var _qty = '';
                    var _lotno = '';
                    
                    //删除下面detail
                    var _index1 = 0;
                    for (var i = 0; i < $scope.selectedList.length; i++) {
                        if ($scope.selectedList[i].barcode == $scope.warehouseInfo.plot_info_detail[index].barcode) {                          
                            _index1 = i;
                            _qty = $scope.selectedList[i].lotqty;
                            _lotno = $scope.selectedList[i].lotno;
                            break;
                        }

                    }



                    var count = 1;
                    var oldbacode = '';
                    for (var i = 0; i < $scope.selectedList.length; i++) {                     
                        if ($scope.selectedList[i].barcode == oldbacode && oldbacode == $scope.warehouseInfo.plot_info_detail[index].barcode) {
                            count = count + i - _index1;
                        } 
                         oldbacode = $scope.selectedList[i].barcode;
                    }
                    $scope.selectedList.splice(_index1, count);
                    $scope.warehouseInfo.plot_info_detail.splice(_index, 1);
                    //删除入库资料的数据
                    for (var i = 0 ; i < $scope.warehouseInfo.plot_detail.length; i++) {
                        if ($scope.warehouseInfo.plot_detail[i].lotno == _lotno) {
                            $scope.warehouseInfo.plot_detail[i].lotno_qty = parseInt($scope.warehouseInfo.plot_detail[i].lotno_qty) - parseInt(_qty);
                        }
                        // 20230217 modify by Alan for #127937: 當數量小於0時應從入库资料移除
                        if($scope.warehouseInfo.plot_detail[i].lotno_qty <= 0) {
                            $scope.warehouseInfo.plot_detail.splice(i, 1);
                        }
                    }
                    
                };

                $scope.openStorage = function () {
                    $mdDialog.dialog(
                        'module/moduleB/program/B04/B0405/B0405_SearchPlot.tmp.html',
                        storageController
                    );
                };

                function storageController(dialog) {
                  
                    var controller = {
                        type:$scope.type,
                        warehouseInfo: $scope.warehouseInfo,
                        //成品庫
                        loadProductWarehouse: function () {
                            // 良品 = 1 , 不良品 =3
                            var conditionvalue = 1;
                            if($scope.type == 1){
                                conditionvalue = 3;
                            } else {
                                conditionvalue = 1;
                            }
                            pageNumberInfoGet({
                                page_mode : '13',
                                query_condition_info : [
                                    { column_name:'InventoryType', query_mode:'0', value:conditionvalue }
                                ]
                            }, function (response) {
                                $scope.$root.showSelect({
                                    title: $filter('translate')('B0405.otherTitle.column1'),
                                    label: function(item){
                                        return item.page_no + ' ('+ item.page_name +')';
                                    },
                                    code: 'page_no',
                                    selectCode: $scope.warehouseInfo.product_warehouse,
                                    list: response,
                                    confirm: function (item, dialog) {
                                        dialog.hide();
                                        $scope.warehouseInfo.product_warehouse_name = item.page_name;
                                        $scope.warehouseInfo.product_warehouse = item.page_no;

                                        $scope.warehouseInfo.storage = '';
                                        $scope.warehouseInfo.storage_display = '';
                                    }
                                });
                            });
                        },
                        //儲位
                        loadStorage: function () {
                            if($scope.warehouseInfo.product_warehouse != ''){
                                pageNumberInfoGet({page_mode: 14, query_condition_info :[
                                    {column_name:'InventoryNo', query_mode:'0', value:$scope.warehouseInfo.product_warehouse}
                                ]}, function (response) {
                                    $scope.$root.showSelect({
                                        title: $filter('translate')('B0405.otherTitle.column1'),
                                        label: function(item){
                                            return item.page_no + ' ('+ item.page_name +')';
                                        },
                                        code: 'page_no',
                                        selectCode: $scope.warehouseInfo.storage,
                                        list: response,
                                        confirm: function (item, dialog) {
                                            dialog.hide();
                                            $scope.warehouseInfo.storage = item.page_no;
                                            $scope.warehouseInfo.storage_display = item.page_name;
                                        }
                                    });
                                });
                            } else {
                                $scope.$root.showAlert($filter('translate')('B0405.msg.product_warehouse_empty'));
                            }

                        },
                        loadERP: function () {
                            $rootScope.showQueryList({
                                pageRecord:50,
                                header : [
                                    {label:$filter('translate')('B0216.queryList.column3_1'), code:'page_no'},
                                    {label:$filter('translate')('B0216.queryList.column3_2'), code:'page_name'}
                                ],
                                query: function(conditions, feedback){
                                    $MMWService.sendToServer({
                                        uri: 'ServicesSTD.Module_SYS.erp_document_type_get',
                                        content: { doc_type:$scope.do_flag == 0?'1':'6' },
                                        success: function (data) {
                                            feedback(data);
                                        }
                                    });
                                },
                                selectCode:$scope.warehouseInfo.erp_doc_type,
                                confirm : function(selectItem, dialog){
                                    $scope.warehouseInfo.erp_doc_type = selectItem.page_no;
                                    dialog.hide();
                                }
                            });
                        },
                        back: function () {
                            $scope.warehouseInfo.product_warehouse_name = '';
                            $scope.warehouseInfo.product_warehouse = '';
                            $scope.warehouseInfo.storage = '';
                            $scope.warehouseInfo.storage_display = '';
                            $scope.warehouseInfo.erp_doc_type = '';
                            dialog.hide();
                        },
                        confirm: function () {

                            if($scope.type==0){
                                if($scope.warehouseInfo.product_warehouse.length == 0) {
                                    $rootScope.showAlert($filter('translate')('B0405.showAlert.column3'));
                                } else {
                                    dialog.hide();
                                    warehousePlotProcess();
                                }
                            } else if($scope.type == 1){
                                dialog.hide();
                                warehousePlotProcess();
                            }
                        }
                    }
                    return controller;
                }

                //取得單號
                // 1 工單編號 6產品編號 13成品庫 14儲位
                function pageNumberInfoGet(content, feedback) {
                    $MMWService.pageNumberInfoGet(
                        content
                        , function (itemList) {
                            feedback(itemList);
                        });
                }

                //送出確定的待入庫資料
                //type 0:良品 1:不良品
                function warehousePlotProcess() {
                    var msg = '';
                    var content = {
                        type: $scope.type,
                        product_warehouse: $scope.warehouseInfo.product_warehouse,
                        storage: $scope.warehouseInfo.storage,
                        erp_doc_type: $scope.warehouseInfo.erp_doc_type,
                        do_flag: $scope.do_flag,                       
                        plot_info_detail: []
                    };
                    if($scope.warehouseInfo.select_type == 2){
                        content.type = 2;
                        //20170612 modify by Dustdusk for 新增warehouseInfo.select_type = 4 (作廢)
                    } else if($scope.warehouseInfo.select_type == 4){
                        content.type = 3;
                    }
                    for (var i = 0; i < $scope.warehouseInfo.plot_detail.length; i++) {
                        //20220517 modify by 翰鴻
                        //少了 product_no                        
                        var plot_info_detail = { op_no: $scope.warehouseInfo.plot_detail[i].opno, product_ver: $scope.warehouseInfo.plot_detail[i].product_ver, product_no: $scope.warehouseInfo.plot_detail[i].product_no, plot_no: $scope.warehouseInfo.plot_detail[i].lotno, lot_code: $scope.warehouseInfo.plot_detail[i].lot_code, plot_qty: $scope.warehouseInfo.plot_detail[i].lotno_qty, do_flag: 0 };
                       content.plot_info_detail.push(plot_info_detail);
                    }
                     
                    if(msg == ''){
                        $MMWService.sendToServer({
                            uri: 'ServicesSTD.Module_WIP.warehouse_plot_process',
                            content: content,
                            success: function (data, response) {
                                //20180514 modify by Dustdusk for M#46940:入庫完成的訊息由後台提供 請抓 response.Message
                                var msg = $filter('translate')('B0405.msg.process_success');
                                
                                if(response.Message != undefined && response.Message!=''){
                                    msg = response.Message;
                                    //20230303 modify by 文蔚 for M#128797:入庫後沒反應
                                    $rootScope.showToast(msg)
                                }
                                //20170330 modify by megabytes for 確認存取完後清空                               
                                $scope.selectedList = [];
                               
                                //^_^ ADD BY LYW  20201111 =============begin============== 
                                //功能描述：更新表tblWIPBarCode 
                                insertProcess();
                                //^_^ ADD BY LYW  20201111 ==============END=============== 
  
                            }
                        });
                    } else {
                        $scope.$root.showAlert(msg);
                    }
                }
                //更新表tblWIPBarCode
                function insertProcess() {

                    var content = {                       
                        detail: []
                    };
                    content.detail = $scope.warehouseInfo.plot_info_detail;                   
                    $MMWService.sendToServer({
                        uri: 'ServicesSTD.Module_SN.insert_tblwipbarcode',
                        content: content,
                        success: function (data) {
                            $scope.warehouseInfo.plot_info_detail = [];
                        }
                    });

                }

           
            }
    ];
});
